/*
 * Created on 2005-9-5
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.jedi;

import com.tss.util.DbConn;
import com.tss.util.DbRs;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Board extends BaseObj {
	public Board() {}
	public Board(String id) {this.id = id;}
	
	public void insert() {
		clearErr();
		DbConn conn = new DbConn();
		try {
			String sql = "";
			setId(KeyGen.nextID(""));
			
			sql = "insert into t_board_info (" +
				" list_id,msg_info,author_id,author_name,issue_time" +
				" ) values (?,?,?,?,?)";
			conn.prepare(sql);
			conn.setString(1,getId());
			conn.setString(2,getMsgInfo());
			conn.setString(3,getAuthorId());
			conn.setString(4,getAuthorName());
			conn.setString(5,getIssueTime());
			conn.executeUpdate();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		finally {
			conn.close();
		}
	}
	
	public void update() {
		clearErr();
		DbConn conn = new DbConn();
		try {
			if (getId().trim().equals("")) {
				setErr("记录不存在");
				return;
			}
			String sql = "update t_board_info set" +
				" msg_info = ? , author_id = ? , author_name = ? , issue_time" +
				" where list_id = ?";
			conn.prepare(sql);
			conn.setString(1,getMsgInfo());
			conn.setString(2,getAuthorId());
			conn.setString(3,getAuthorName());
			conn.setString(4,getIssueTime());
			conn.setString(5,getId());
			conn.executeUpdate();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		finally {
			conn.close();
		}
	}
	
	public void delete() {
		clearErr();
		DbConn conn = new DbConn();
		DbRs rs = null;
		try {
			String sql = "";
			if (getId().trim().equals("")) {
				setErr("记录不存在!");
				return;
			}
			sql = "delete from t_board_info where list_id = ?";
			conn.prepare(sql);
			conn.setString(1,getId());
			conn.executeUpdate();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		finally {
			conn.close();
		}
	}
	
	public String getId() {return id;}
	public String getMsgInfo() {return msgInfo;}
	public String getAuthorId() {return authorId;}
	public String getAuthorName() {return authorName;}
	public String getIssueTime() {return issueTime;}

	protected void setId(String id) {this.id = id;}
	public void setMsgInfo(String msgInfo) {this.msgInfo = msgInfo;}
	public void setAuthorId(String authorId) {this.authorId = authorId;}
	public void setAuthorName(String authorName) {this.authorName = authorName;}
	public void setIssueTime(String issueTime) {this.issueTime = issueTime;}

	private String id = "";
	private String msgInfo = "";
	private String authorId = "";
	private String authorName = "";
	private String issueTime = "";
}
